package com.share.common.enums;

import lombok.Getter;

import java.util.Optional;

@Getter
public enum ProfileEnvEnum {
    DEV("dev", "开发环境"),
    TEST("test", "测试环境"),
    PROD("prod", "生产环境");

    public String code;
    public String name;

    private ProfileEnvEnum(final String code, final String name) {
        this.code = code;
        this.name = name;
    }

    public static ProfileEnvEnum toEnum(final String code) {
        for (final ProfileEnvEnum tag : ProfileEnvEnum.values()) {
            if (tag.code.equals(code)) {
                return tag;
            }
        }
        return null;
    }

    public static String toName(final String code) {
        return Optional.ofNullable(toEnum(code)).map(item -> item.name).orElse(null);
    }

}
